
public class MergeSort {

	
	static void mergeSort(int p, int r, int[] a){
		if(p == r){
			return;
		}
		int m = (p+r)/2;
		mergeSort(p, m, a);
		mergeSort(m+1, r, a);
		
		int[] left = new int[m-p+1];
		int[] right = new int[r-m];
		for (int i = p; i <= m; i++) {
			left[i-p] = a[i];
		}
		for (int i = m+1; i <= r ; i++) {
			right[i-(m+1)] = a[i];
		}
		int[] res = merge(left, right);
		
		for (int i = 0; i < res.length; i++) {
			a[i+p] = res[i];
		}
	
		
	}
	
	
	
	public static void main(String[] args) {
		

	}

}
